//节点
const tbodyEle = document.querySelector('tbody')
let arr = []
/**
 * 数据引入
 */
function productData() {
    $.ajax({
        type: "get",
        url: "http://47.107.88.7:8089/api/shop/category/list",
        // data: {
        //     pageNo: 1,
        //     pageSize: 10
        // },
        dataType: "json",
        success: function (data) {
            let arrList = data.resultInfo.list
            for (let i = 0; i < arrList.length; i++) {
                arr.push(arrList[i])
            }
            rander()
            checks()
        }
    });
}
productData()
/**
 * 渲染到页面
 */
function rander() {
    let str = `<tr>
        <th><input type="checkbox" class="checkbox-all">全选</th>
        <th>类型编码</th>
        <th>商品类型</th>
        <th colspan="2">操作</th>
        </tr>`
    for (let i = 0; i < arr.length; i++) {
        str += `<tr>
                <td> <input type="checkbox" class="checkbox-item"></td>
                <td>${arr[i].id}</td>
                <td>${arr[i].name}</td>
                <td><a href="#" class="delete">删除</a> </td>
                <td><a href="#">编辑</a></td>
            </tr>`
    }
    tbodyEle.innerHTML = str
    deleteProduct()
}
/**
 * 删除商品
 */
function deleteProduct() {
    $('.delete').click(function () {
        $.ajax({
            type: "get",
            url: "http://47.107.88.7:8089/api/shop/category/delete",
            data: {
                id: $(this).parent().parent().children().first().next().html()
            },
            dataType: "json",
            success: function (data) {
                if (data.resultCode == 1) {
                    arr = []
                    productData()
                    $('p').css('display','block')
                    setTimeout("$('p').css('display','none')",2000)
                }
            }
        });
    })
}